package com.gdssoft.framework.service.system.impl;
/*
 *  捷达世软件(深圳)有限公司
 *  Copyright (C) 2008-2010 ShenZhen JieDaShi Software Limited Company. 
*/
import java.util.List;

import com.gdssoft.core.command.QueryFilter;
import com.gdssoft.core.service.impl.BaseServiceImpl;
import com.gdssoft.core.util.ContextUtil;
import com.gdssoft.core.web.paging.PagingBean;
import com.gdssoft.framework.dao.system.DepartmentDao;
import com.gdssoft.framework.model.system.Department;
import com.gdssoft.framework.service.system.DepartmentService;

public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements
		DepartmentService {
	
	private DepartmentDao dao;
	
	public DepartmentServiceImpl(DepartmentDao dao) {
		super(dao);
		this.dao=dao;
	}
	
	@Override
	public List<Department> findByParentId(Long parentId) {
		return findByParentId(parentId, null);
	}
	
	@Override
	public List<Department> findByParentId(Long parentId, PagingBean pb) {
		return dao.findByParentId(parentId, pb);
	}
	
	@Override
	public List<Department> findByPath(String path) {
		return findByPath(path, null);
	}
	
	@Override
	public List<Department> findByPath(String path, PagingBean pb) {
		return dao.findByPath(path, pb);
	}

	@Override
	public List<Department> findByParentId(Long parentId, Integer depLevel,
			PagingBean pb) {
		return dao.findByParentId(parentId,depLevel, pb);
	}

	@Override
	public List<Department> getByOfficeId(Long officeId) {
		return dao.getByOfficeId(officeId,null);
	}

	@Override
	public List<Department> getByCompanyId(Long companyId) {
		return dao.getByCompanyId(companyId,null);
	}

	@Override
	public List<Department> findByPath(String path, int level) {
		return dao.findByPath(path, level);
	}
	
	@Override
	public String getSubDepIds() {
		String ids = "";
		QueryFilter filter = new QueryFilter(0,Integer.MAX_VALUE);
		filter.addFilter("Q_depLevel_N_EQ", "2");//'0:保留，1:公司，2:管理处'
		filter.addFilter("Q_path_S_LFK", ContextUtil.getCurrentUser().getEmployee().getDepartment().getPath());
		List<Department> list = getAll(filter);
		if(list.size()>0){
			for (Department department : list) {
				ids += department.getDepId()+",";		
			}
			ids = ids.substring(0, ids.length()-1);
		}
		return ids;
	}

	@Override
	public String getSubDepCodes() {
		String codes = "";
		QueryFilter filter = new QueryFilter(0,Integer.MAX_VALUE);
		filter.addFilter("Q_depLevel_N_EQ", "2");//'0:保留，1:公司，2:管理处'
		filter.addFilter("Q_path_S_LFK", ContextUtil.getCurrentUser().getEmployee().getDepartment().getPath());
		List<Department> list = getAll(filter);
		if(list.size()>0){
			for (Department department : list) {
				codes += department.getDepCode()+",";		
			}
			codes = codes.substring(0, codes.length()-1);
		}
		return codes;
	}
}
